#pragma once
#include "base_buf.h"
#include <queue>

namespace fly {

	namespace jld{

		namespace buffer {	

			typedef boost::shared_ptr<asio::streambuf::const_buffers_type> const_buf_ptr;

			enum TARGET
			{
				T_SELF,
				T_SYN_TO,
				T_SYN_FROM,
				T_SYN_BOTH,
				T_ALL
			};
			struct send_packet
			{
				const_buf_ptr buf;
				TARGET target;
			};
			class send_buf
				:public base_buf
			{
			private:
				const size_t min_send_size_;
				bool is_send_;
				//ensure all connections can safely send the const buffer and
				//each time send buffer is different (reset)
				//it will be reuse or reset when all connections finished sending
				const_buf_ptr const_buf_;
				queue<send_packet> packets_;
			public:
				send_buf();
				virtual ~send_buf();
				bool is_send();
				void set_const_buf();
				const TARGET& target();
				bool serialize_to_send(const PID& pid, const TARGET& target, google::protobuf::Message& message);
				queue<send_packet>& packets();
			};

		}
	}
}